package com.lianjia.analysis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;

/**
 * Jackson配置类
 * 自定义ObjectMapper配置，确保JSON序列化不包含类型信息
 */
@Configuration
public class JacksonConfig {

    /**
     * 创建自定义的ObjectMapper
     * 禁用默认类型信息输出
     */
    @Bean
    @Primary
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        
        // 创建新的JsonMapper，禁用默认类型信息
        JsonMapper jsonMapper = JsonMapper.builder()
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .build();
        
        // 复制JsonMapper的配置到ObjectMapper
        objectMapper = jsonMapper;
        
        return objectMapper;
    }
} 